<template>

      <div id="contain">
        <van-nav-bar title="程序猿头条 - 注册" />
        <h2>Register</h2>

        <div class="form">
          <label>用户名：</label><input type="text" v-model.trim="name"><br/>
        </div>
        <div class="form">
          <label>密码：</label><input type="password" v-model.trim="password"><br/>
        </div>
        <div class="form">
          <label>邮箱：</label><input type="email" v-model.trim="mail"><br/>
        </div>
        <div class="form">
          <label>手机号：</label><input type="tel" v-model.trim="tel"><br/>
        </div>
        <van-button @click.prevent="handlefinish">提交</van-button>
        <van-button
          round
          block
          type="info" @click="relogin" class="btn">已有账号返回登录</van-button>
      </div>
</template>
<script>
export default {
    name: 'Register',
    props: {
    msg: String
  },
  data() {
    return {
      name: '小郭',
      password: '246810',
      mail: '123@qq.com',
      tel: '13888888888'
  }
  },
methods: {
  // 点击完成按钮触发handlefinish
    handlefinish: function() {
      if (localStorage.name === this.name) {
        alert('用户名已存在')// 如果用户名已存在则无法注册
      } else if (this.name === '') {
        alert('用户名不能为空')
      } else { // 将新用户信息存储到localStorage
        localStorage.setItem('name', this.name)
        localStorage.setItem('password', this.password)
        localStorage.setItem('mail', this.mail)
        localStorage.setItem('tel', this.tel)
        localStorage.setItem('s', 'false')
        alert('注册成功')
        this.$router.replace('/login')// 完成注册后跳转至登录页面
      }
    },
    relogin() {
      this.$router.replace('/login')
    }
  }
}
</script>
<style scoped>
#contain{
  width: 100%;
  height: 100%;
  position: absolute;
/*  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%); */
  background:white;
  text-align: center;
  border-radius: 20px;
}
#contain h1{
  color: black;
}
.form{
  color: black;
  margin-top: 60px;
  font-size: 20px;
  text-align: left;
}
.btn{
  width: 80%;
  font-size: 25px !important;
  font: normal 13px/100% Verdana,Tahoma,sans-serif;
  margin-left: 10%;
}
label{
  float:left;
  width: 5em;
  margin-right: 1em;
  text-align: right;
}
input,textarea{
  margin-left: 10px;
  padding: 4px;
  border: solid 1px #4e5ef3;
  outline: 0;
  font: normal 13px/100% Verdana,Tahoma,sans-serif;
  width: 200px;
  height: 20px;
  background:#f1f1f190;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
}
input:hover,textarea:hover,input:focus,textarea:focus{border-color:#0d0aa1;}
button{
  position: relative;
  height: 33px;
  width: 80%;
  background: rgba(35, 19, 252, 0.425);
  border-radius: 10px;
  margin-top: 38px;
  box-shadow: none;
  color: blue;
}
</style>
